package com.hotelmanage.hm.controller;

import com.hotelmanage.hm.service.ServiceService;
import com.hotelmanage.hm.vo.ServiceVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.xml.ws.Service;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/service")
public class ServiceController {

    @Autowired
    private ServiceService serviceService;

    @RequestMapping("get")
    public Object get(@RequestParam Integer id){
        Map<String,Object> map = new HashMap<String, Object>();
        map.put("service",serviceService.get(id));
        return map;
    }

    @RequestMapping("getAll")
    public Object getAll(){
        Map<String,Object> map = new HashMap<String, Object>();
        map.put("service",serviceService.getAll());
        return map;
    }

    @RequestMapping("newService")
    public Object newService(@RequestBody ServiceVO serviceVO){
        Map<String,Object> map = new HashMap<String, Object>();


        int result = serviceService.newService(serviceVO);
        if(result==0){
            map.put("status",404);
            map.put("desc","新增失败");
        }else{
            map.put("status",200);
            map.put("desc","新增成功");
        }
        return map;
    }

    @RequestMapping("editService")
    public Object editService(@RequestBody ServiceVO serviceVO){
        Map<String,Object> map = new HashMap<String, Object>();


        int result = serviceService.editService(serviceVO);
        if(result==0){
            map.put("status",404);
            map.put("desc","编辑失败");
        }else{
            map.put("status",200);
            map.put("desc","编辑成功");
        }
        return map;
    }
}
